$(document).ready(function(){
	$(".top_banner_title").click(function(){
		$(".top_banner_holder").css("display")=="none"?$(".top_banner_holder").slideDown():$(".top_banner_holder").slideUp();
	});
	$(".right_banner_title").click(function(){
		$(".right_banner_holder").css("display")=="none"?$(".right_banner_holder").slideDown():$(".right_banner_holder").slideUp();
	});
	$(".bottom_banner_title").click(function(){
		$(".bottom_banner_holder").css("display")=="none"?$(".bottom_banner_holder").slideDown():$(".bottom_banner_holder").slideUp();
	});
	
	function getPublish( object ){
		$(object).click(function(){
			$.ajax({
				url:"?com=resource&action=published",
				type:"POST",
				data:{
					id:$(object).attr("bid"),
					publish:$(object).attr("value")
				},
				success:function(result){
					result = parseInt( result );
					var publish = parseInt( $(object).attr("value") );
					switch(publish){ 
					case 0 :
						switch(result){
						case 0 :
							// failed to published
							break;
						case 1 :
							// success to published
							$(object).attr("class","rsrc_notpublished publish");
							$(object).attr("value",1);
							break;
						}
						break;
					case 1 :
						switch(result){
							case 0 :
								// failed to unpublished
								break;
							case 1 :
								// success to unpublished
								$(object).attr("class","rsrc_published publish");
								$(object).attr("value",0);
								break;
						}
						break;
					}
				}
			});
		});
	}
	var publishes = $(".publish").toArray();
	for(var i in publishes ){
		getPublish(publishes[i]);
	}
});

function deletebanner(id){
	$.ajax({
		url:"?com=banner&action=delete",
		type:"POST",
		data:{
			id:id
		},
		success:function(result){
			$(".banner"+id).slideUp();
			$(".banner"+id).remove();
		}
	});
}
az.control(document).ready(function(){
	/*
	az.control("#tinymce").change(function(){
		alert( "me" );
	});
	*/
	
	if ( az.control(".banner_published")!==null ){
		var publisheds = az.control(".banner_published");
		for( var index in publisheds ){
			getPublish(publisheds[index]);
		}
	}
	if ( az.control(".banner_unpublished")!==null ){
		var publisheds = az.control(".banner_unpublished");
		for( var index in publisheds ){
			getPublish(publisheds[index]);
		}
	}
	
	if ( az.control("#btnPreview")!==null ){
		az.control("#btnPreview").click(function(){
			az.control("#preivew").html( tinyMCE.get("content").getContent() ) ;
		});
	}
	
	if ( az.control("#style")!==null ){
		az.control("#style").change(function(){
			var style = parseInt( az.control("#style").value );
			az.control("#preivew").setAttr("class","");
			az.control("#preivew").setAttr("class","preview banner_item_note"+(style==0?"":style));
		});
	}
});